﻿using System;
using System.Windows.Automation;	

namespace RobotUI.Controls
{
	/// <summary>
	/// Text Edit control
	/// </summary>
	public class Edit : Control
	{
		
		public Edit(AutomationElement element) : base(element) { }
		
		public override void SetValue(string data)
		{
			//set
			var valpat = _element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
            valpat.SetValue(data);
            //check
            var check = GetValue();
            if (!String.Equals(data,check,StringComparison.CurrentCultureIgnoreCase)) throw new Exception("SetValue check of GetValue failed");
            
		}
		
		public override string GetValue()
		{
			Object valpat = null;;
            if (true == _element.TryGetCurrentPattern(ValuePattern.Pattern,out valpat))
            {
            	return (valpat as ValuePattern).Current.Value;
            }
            else
            {
            	return _element.Current.Name;
            }
		}

		public override void Click()
		{
			throw new NotImplementedException("SetValue not supported for Edit control");
		}
		
	}
}
